package com.fh.wanandroid.ui.knowledge.presenter;

import android.util.Log;

import com.fh.wanandroid.base.BaseResponse;
import com.fh.wanandroid.net.RetrofitHelper;
import com.fh.wanandroid.ui.knowledge.KnowledgeDataList;
import com.fh.wanandroid.ui.knowledge.contract.KnowledgeContract;
import com.fh.wanandroid.utils.NetErrorUtil;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class KnowledgePresenter extends  KnowledgeContract.Presenter {

    @Override
  public  void loadInitData() {

        mCompositeDisposable.add(RetrofitHelper.createArticleApi().getKnowledgeData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseResponse<List<KnowledgeDataList>>>() {
                    @Override
                    public void accept(BaseResponse<List<KnowledgeDataList>> knowledgeDatas) throws Exception {
                        mView.refreshKnowledge(knowledgeDatas.getData());
//                        mView.appendData(girlBean.getResults());
//                        mView.refreshArticle(articleBean);
                        Log.e("articleBean","------------------articleBean:"+knowledgeDatas.getData().toString());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable t) throws Exception {
//                        mView.loadArticlesFail(NetErrorUtil.handleThrowable(t));
                        mView.loadDataFail(NetErrorUtil.handleThrowable(t));
                    }
                }));

    }

    @Override
    public void loadMoreData() {

        mView.appendKnowledge(null);
    }
}
